package com.czk.springdatar2dbc.config.converter;

import com.czk.springdatar2dbc.vo.BookVO;
import io.r2dbc.spi.Row;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.ReadingConverter;

import java.time.Instant;

/**
 * @Author: chenzhangkun
 * @CreateTime: 2025-05-28
 * @Description: 当方法签名返回BOOKVO时，会调用这个转换器
 * @Version: 1.0
 */
@ReadingConverter
public class BookConverter implements Converter<Row, BookVO> {
    @Override
    public BookVO convert(Row source) {
        BookVO book = new BookVO();
        book.setId(source.get("id", Long.class));
        book.setTitle(source.get("title", String.class));
        book.setAuthorId(source.get("author_id", Long.class));
        book.setPublishTime(source.get("publish_time", Instant.class));
        book.setName(source.get("name", String.class));
        return book;
    }
}
